import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex);

let state = {
  //当个商品的加入购物车的数量
  count: 0,
  // 法国直邮
  aFrench: [],
  // 日本直邮
  aJapan: [],
  //英国直邮
  aEnglish: [],
  //加入购物车商品列表
  cartList: []
};

const mutations = {
  add(state){
    state.count ++
  },
  decrease(state){
    state.count --
  },
  addCar(state,{food}) {
    let cart = state.cartList;
    // if(cart[food]) {
    //   food['num']++;
    // } else {
    //   food['num']++;
    //   cart.push(food)
    // }
    // let goodsDetail = {
    //   ID: id,
    //   img: img,
    //   name: name,
    //   price: price,
    //   standard: standard,
    //   address: address,
    //   brand: brand,
    //   addressImg: addressImg,
    //   num: 1
    // }
    console.log(food);
  }
};
const actions = {
  add(state) {
    state.commit('add')
  },
  decrease(state){
    state.commit('decrease')
  },
  addCar(state){
    state.commit('addCar')
  }
}

const getters = {
  count(state){
    return state.count
  },
  cartList(state){
    return state.cartList
  }
}

export default new Vuex.Store({
  state,
  mutations,
  actions,
  getters
})
